$(function() {
	//初始化
	Begin();
})



function Update() {
	table.getData({
		orgCode: "000000",
		searchValue: "",
		status: ""
	}, true);
}

function Edit() {
	table.on("handleEdit", function(index, row) {
		var self = this;
		this.$confirm("确认提醒\n" + row.dept + "/" + row.user + "？")
			.then(function() {
				row.status = "1";
				done();
			})
			.catch(function() {});
		VanyAjax.prototype.hideLoading()
	});
};

function Search() {
	table.on("search", function(val) {
		table.getData({
			orgCode: "000000",
			searchValue: val,
			status: ""
		}, true);
	});
};

////////////--------------统计图表--------------------////////////
var xAxisData = [],
	yAxisData = [],
	option,
	tabFirstClick;

//参数为当天24小时
$.ajax({
	type: "get",
	url: "templates/authority/messageHistory/json/data.json",
	async: true,
	success: function(data) {
		var echartFirst = echarts.init(document.getElementById('chartFirst'));
		for(var i = 0; i < data.resultData.rows.length; i++) {
			xAxisData.push(data.resultData.rows[i].setTime);
			yAxisData.push(data.resultData.rows[i].number);
		}
		EchartOption(echartFirst);
	}
});

var chartTab = new Vue({
	el: "#chartTab",
	data: function() {
		return {
			activeName: 'chartFirst'
		}
	},
	methods: {
		handleClick:function(tab, event) {
			//tab点击是否加载
			if(tab.index == tabFirstClick) {
				return;
			} else {
				xAxisData = [];
				yAxisData = [];
				tabFirstClick = tab.index;
			}
			if(tab.index == 1) {
				//参数为最新一周
				$.ajax({
					type: "get",
					url: "templates/authority/messageHistory/json/data.json",
					async: true,
					success: function(data) {
						var echartSecond = echarts.init(document.getElementById('chartSecond'));
						for(var i = 0; i < data.resultData.rows.length; i++) {
							xAxisData.push(data.resultData.rows[i].setTime);
							yAxisData.push(data.resultData.rows[i].number);
						}
						EchartOption(echartSecond);
					}
				});
			}
			if(tab.index == 2) {
				//参数为最新一月
				$.ajax({
					type: "get",
					url: "templates/authority/messageHistory/json/data.json",
					async: true,
					success: function(data) {
						var echartThird = echarts.init(document.getElementById('chartThird'));
						for(var i = 0; i < data.resultData.rows.length; i++) {
							xAxisData.push(data.resultData.rows[i].setTime);
							yAxisData.push(data.resultData.rows[i].number);
						}
						EchartOption(echartThird);
					}
				});
			}
		}
	}
})

function EchartOption(obj) {
	 option = {
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'line',
				label: {
					backgroundColor: '#6a7985'
				}
			}
		},
		toolbox: {
			feature: {
				saveAsImage: {}
			}
		},
		color: ['#c6f5e5'],
		xAxis: [{
			type: 'category',
			boundaryGap: false,
			data: xAxisData
		}],
		yAxis: [{
			type: 'value'
		}],
		series: [{
			name: '确认人数',
			type: 'line',
			areaStyle: {
				normal: {}
			},
			data: yAxisData
		}]
	};
	//每次窗口大小改变的时候都会触发onresize事件，这个时候我们将echarts对象的尺寸赋值给窗口的大小这个属性，从而实现图表对象与窗口对象的尺寸一致的情况
	window.onresize = obj.resize;
	obj.setOption(option);
}

//初始化
function Begin() {
	//面包屑
	new Vue().$mount('#crumbs');
	//获取整个菜单
	new Vue().$mount('#menuL');
	//左菜单滚动
	var oTop = $(".vany_authority").offset().top + 14;
	var sTop = 0;
	$(".vany_authority").scroll(function() {
		sTop = $(this).scrollTop();
		if(sTop >= oTop) {
			$("#menuL").css({
				"position": "fixed",
				"top": "60px"
			});
		} else {
			$("#menuL").css({
				"position": "absolute",
				"top": "0"
			});
		}
	});
	sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
}